import pymysql


def exec_sql(sql,is_get_list=False, is_get_one=False, is_modify=False):
    db = None
    cur = None
    try:
        db = pymysql.connect(host="localhost", port=3306, user="root", password="root", database="django", charset="utf8")
        cur = db.cursor(pymysql.cursors.DictCursor)
        if is_modify:
            cur.execute(sql)
            db.commit()
            return "modify success"
        if is_get_list:
            cur.execute(sql)
            query_set = cur.fetchall()
            return query_set
        if is_get_one:
            cur.execute(sql)
            query_set = cur.fetchone()
            return query_set
    except Exception as e:
        print(e)
        return None
    finally:
        cur.close()
        db.close()




